{extend name="layout/iframe" /}

{block name="content"}
<div class="row">
    <div class="col-xs-12">
        <div class="box box-success">
            <div class="box-body">
                <form action="{:url('admin/'.strtolower($model).'/addpost')}" class="form-horizontal form post-form" method="post" enctype="multipart/form-data">
                    <div class="form-body">
                        <div class="row">
                            <div class="col-md-9">
                                <div class="form-group">
                                    <label class="control-label col-md-3">
                                        选择图片
                                    </label>
                                    <div class="col-md-9">
                                        <div id="upload-image">
                                            <span id="upload-btn" data-multi="true" data-field="imgUrl">
                                                <!--<input type="hidden" class="form-control" id="imgUrl" data-required="1" name="imgUrl[]" value="">-->
                                                <img src="__STATIC__/admin/img/default.png" alt="图片上传" style="width: 100px;height: 100px;" />
                                            </span>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <hr />

                        <div class="form-actions">
                            <div class="row">
                                <div class="col-md-12">
                                    <div class="form-group">
                                        <label class="col-md-3 control-label"></label>
                                        <div class="col-md-9">
                                            <button type="button" class="btn btn-success submit-btn">确定</button>
                                            <button type="button" class="btn btn-default cancel-btn">取消</button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<input type="hidden" class="token_url" value="{:url('admin/Image/token')}">
<input type="hidden" class="record_url" value="{:url('admin/Image/record')}">
<input type="hidden" class="delimage_url" value="{:url('admin/Image/delete')}">

{/block}

{block name="pagescript"}
<script src="__STATIC__/admin/js/qiniu/plupload.full.min.js" type="text/javascript"></script>
<script src="__STATIC__/admin/js/qiniu/qiniu.js" type="text/javascript"></script>
<script src="__STATIC__/admin/js/qiniu/custom.js" type="text/javascript"></script>
<script src="__STATIC__/admin/js/qiniu/qiniuConfig.js" type="text/javascript"></script>

<script src="__STATIC__/admin/js/uploadfile.js" type="text/javascript"></script>
<script>
    // 提交
    $('.submit-btn').on('click', function(){
        //$('.post-form').submit();
        var url = $('.post-form').attr('action');
        var data = $('.post-form').serialize();

        if(data == ''){
            layer.msg('请选择图片');
            return false;
        }

        $.ajax({
            type : 'post',
            url : url,
            data : data,
            dataType : 'json',
            success : function(data){
                if(data.status == 1){
                    close_iframe();
                    parent.window.location.reload();
                }else{
                    layer.msg(data.msg);
                }
            }
        });
        return false;
    });

    // 取消
    $('.cancel-btn').on('click', function(){
        close_iframe();
    });

    function close_iframe(){
        //先得到当前iframe层的索引
        var index = parent.layer.getFrameIndex(window.name);
        //再执行关闭
        parent.layer.close(index);
    }
</script>
{/block}